﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMTC.Model.Model;
using System.Data.Common;
using IMPlant.Core.Data.Unity;
using System.Data;

namespace SMTC.Dao.BaseInfo
{
    public class ProductionUnitQueryDao : BaseDao
    {
        private const string SQL_SELECT_PU = @"SELECT PUID,
	                                            PUType,
	                                            PUCapacity,
	                                            Para,
	                                            ModifyPerson,
	                                            ModifyDateTime,
                                                EffectiveTimeStart,
                                                EffectiveTimeEnd,
	                                            LineID FROM dbo.SMT_ProductionUnit
	                                            WHERE PUType like @PUType and PUCapacity like @PUCapacity and ModifyPerson like @ModifyPerson 
	                                            AND (ModifyDateTime  between @MaintenanceStartTime  and  @MaintenanceEndTime)
                                                 and 
                                                (EffectiveTimeStart >=@EffectiveTimeStart OR EffectiveTimeStart IS null)
                                                 AND 
                                                 (EffectiveTimeEnd<=@EffectiveTimeEnd OR EffectiveTimeEnd IS null)
                                                 AND PUVersion = @PUVersion order by PUType";

        
        public List<SMT_ProductionUnitModel> GetProductionUnit(Query_PUModel _Query_PUModel)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@PUType",_Query_PUModel.Type)
                ,DBparameterBuild.Build("@PUCapacity",_Query_PUModel.Abilty)
                ,DBparameterBuild.Build("@ModifyPerson",_Query_PUModel.ModifyPer)
                ,DBparameterBuild.Build("@MaintenanceStartTime",_Query_PUModel.MaintenanceStartTime)
                ,DBparameterBuild.Build("@MaintenanceEndTime",_Query_PUModel.MaintenanceEndTime)
                ,DBparameterBuild.Build("@EffectiveTimeStart",_Query_PUModel.EffectiveTimeStart)
                ,DBparameterBuild.Build("@EffectiveTimeEnd",_Query_PUModel.EffectiveTimeEnd)
                ,DBparameterBuild.Build("@PUVersion",_Query_PUModel.PUVersion)
            };
            return DBTemplete.ExcuteGetList<SMT_ProductionUnitModel>(CommandType.Text, SQL_SELECT_PU ,parameters);
        }


        private const string SQL_SELECT_PU_For_SelectList = @"SELECT PUID,
	                                            PUType,
	                                            PUCapacity,
	                                            Para,
	                                            ModifyPerson,
	                                            ModifyDateTime,
                                                EffectiveTimeStart,
                                                EffectiveTimeEnd,
	                                            LineID FROM dbo.SMT_ProductionUnit
	                                            WHERE PUType like @PUType and PUCapacity like @PUCapacity and ModifyPerson like @ModifyPerson 
	                                            AND (ModifyDateTime  between @MaintenanceStartTime  and  @MaintenanceEndTime) and LineID is null
                                                and 
                                                (EffectiveTimeStart >=@EffectiveTimeStart OR EffectiveTimeStart IS null)
                                                 AND 
                                                 (EffectiveTimeEnd<=@EffectiveTimeEnd OR EffectiveTimeEnd IS null)
                                                ";


        public List<SMT_ProductionUnitModel> GetProductionUnitForSelect(Query_PUModel _Query_PUModel)
        {
            DbParameter[] parameters = 
            {
                DBparameterBuild.Build("@PUType",_Query_PUModel.Type)
                ,DBparameterBuild.Build("@PUCapacity",_Query_PUModel.Abilty)
                ,DBparameterBuild.Build("@ModifyPerson",_Query_PUModel.ModifyPer)
                ,DBparameterBuild.Build("@MaintenanceStartTime",_Query_PUModel.MaintenanceStartTime)
                ,DBparameterBuild.Build("@MaintenanceEndTime",_Query_PUModel.MaintenanceEndTime)
                ,DBparameterBuild.Build("@EffectiveTimeStart",_Query_PUModel.EffectiveTimeStart)
                ,DBparameterBuild.Build("@EffectiveTimeEnd",_Query_PUModel.EffectiveTimeEnd)
            };
            return DBTemplete.ExcuteGetList<SMT_ProductionUnitModel>(CommandType.Text, SQL_SELECT_PU_For_SelectList, parameters);
        }
    }
}
